package com.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

/**
 * Created by buguniao on 16/4/16.
 */
public class FutureTaskTest1 {
    public static void main(String[] args) throws Exception {
        FutureTask<String> task = new FutureTask<String>(new Callable<String>() {
            public String call() throws Exception {
                System.out.println("task start .....");
                Thread.sleep(10000);
                System.out.println("task end .....");
                return "xxxxxx";
            }
        });

        new Thread(task).start();

        while(true){
            String rs = null;

            try{
                rs = task.get(1, TimeUnit.SECONDS);
            }catch (Exception e){

            }
            System.out.println("执行结果 ---> "+rs);
            if(rs!=null){
                break;
            }
        }

    }

}
